#include <linux/module.h>
#include <linux/list.h>
#include <linux/init.h>
#include <linux/slab.h>

typedef struct student {
    char name[20];  
	char sex;
    struct student * next;
	struct list_head list;
}Student;

static LIST_HEAD(stu_list);

static int __init list_example_init(void)
{
    Student *stu1;
    Student *stu2;
    Student *stu3;
    Student *stu;

	stu1 = kzalloc(sizeof(stu1), GFP_ATOMIC);
	stu2 = kzalloc(sizeof(stu2), GFP_ATOMIC);
	stu3 = kzalloc(sizeof(stu3), GFP_ATOMIC);


	printk(KERN_INFO "list_init\n");

	stu1->sex = 1;
	stu2->sex = 2;
	stu3->sex = 3;

	list_add(&stu1->list, &stu_list);
	list_add(&stu2->list, &stu_list);
	list_add(&stu3->list, &stu_list);


	list_for_each_entry(stu, &stu_list, list)
		printk(KERN_INFO "stu->sex = %d\n", stu->sex);

	printk(KERN_INFO "end\n");

	return 0;
}

static __exit void list_example_exit(void)
{
	printk(KERN_INFO "unloading list module...\n");
}

module_init(list_example_init);
module_exit(list_example_exit);

MODULE_DESCRIPTION("Example module illustrating the kernel container_of.");
MODULE_AUTHOR("chunli.che");
MODULE_LICENSE("GPL");

